package com.hfy.music.mapper;

import com.hfy.model.vo.CommentVo;
import com.hfy.music.service.impl.CommentServiceImpl;
import org.apache.ibatis.annotations.*;

import java.util.List;

/**
 * @ author 韩
 * time: 2024/5/29 17:21
 */
@Mapper
public interface CommentMapper {

    @Delete("DELETE FROM `music_comment` WHERE `id` = #{commentId}")
    void deleteComment(@Param("commentId") Integer commentId);

    @Select("SELECT biz_id FROM `music_comment` WHERE biz=0 AND id=#{commentId}")
    Integer selectMusicIdByCommentId(@Param("commentId") Integer commentId);

    @Select("SELECT id,account,comment_time commentTime,content FROM `music_comment` WHERE biz=#{biz} AND biz_id=#{bizId} ORDER BY `commentTime` DESC")
    List<CommentVo> queryComments(@Param("biz") Integer biz, @Param("bizId") Integer bizId);

    @Update("UPDATE `comment_count` SET comment_count = comment_count + 1 WHERE biz=#{biz} AND biz_id=#{bizId}")
    void commentIncreaseOne(@Param("biz") Integer biz, @Param("bizId") Integer bizId);

    @Insert("INSERT INTO `comment_count` (`biz`, `biz_id`,`comment_count`) VALUES (#{biz}, #{bizId}, 1)")
    void insertCommentCount(@Param("biz") Integer biz,@Param("bizId") Integer bizId);

    @Select("SELECT id FROM `comment_count` WHERE biz=#{biz} AND biz_id=#{bizId}")
    Integer selectCommentCount(@Param("biz") Integer biz,@Param("bizId") Integer bizId);

    // 根据评论id去查评论详细数据
    @Select("SELECT id,account,comment_time commentTime,content,die FROM `music_comment` WHERE id = #{id}")
    CommentVo queryInfoById(@Param("id") Integer id);

    @Insert("INSERT INTO `music_comment` (`biz`, `account`, `biz_id`, `content`, `comment_time`) VALUES (#{biz},#{account},#{bizId},#{content},#{now})")
    @Options(useGeneratedKeys = true, keyProperty = "id", keyColumn = "id")
    void addComment(CommentServiceImpl.AddCommentBo addCommentBo);
}
